package main

import (
	"fmt"
	"sort"
)

func main() {
	// 创建map
	// ages := make(map[string]int)
	// ages["alice"] = 31
	// ages["charlie"] = 32
	//or
	ages := map[string]int{
		"a": 1,
		"b": 2,
	}
	ages["bob"] = ages["bob"] + 1
	fmt.Println(ages)
	// 顺序随机
	for name, _ := range ages {
		fmt.Println(name)
	}

	//要排序要借别的结构排序
	var names []string
	for name := range ages {
		names = append(names, name)
	}

	sort.Strings(names)

	for _, name := range names {
		fmt.Printf("%s\t%d\n", name, ages[name])
	}

	var emptyMap map[string]int
	fmt.Println(emptyMap == nil)    // "true"
	fmt.Println(len(emptyMap) == 0) // "true"
}
